﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace homework5
{
    public class OrderDetails
    {

        public OrderDetails()
        {
        }

        public OrderDetails(int orderDetailsID,List<Goods> goods)
        {
            OrderDetailsId = orderDetailsID;
            Good = goods;
            Money = 0;
            foreach(Goods good in goods)
            {
                Money += good.Money;
            }
        }

        public int OrderDetailsId
        {
            get;set;
        }
        public List<Goods> Good
        {
            get;set;
        }
        public double Money
        {
            get;set;
        }

        public override bool Equals(object obj)
        {
            var details = obj as OrderDetails;
            return details != null &&
                   OrderDetailsId == details.OrderDetailsId &&
                   EqualityComparer<List<Goods>>.Default.Equals(Good, details.Good) &&
                   Money == details.Money;
        }

        public override int GetHashCode()
        {
            var hashCode = 1790003385;
            hashCode = hashCode * -1521134295 + OrderDetailsId.GetHashCode();
            hashCode = hashCode * -1521134295 + EqualityComparer<List<Goods>>.Default.GetHashCode(Good);
            hashCode = hashCode * -1521134295 + Money.GetHashCode();
            return hashCode;
        }

        public override string ToString()
        {
            return Good.ToString()+ $"，总金额：{Money}";
        }
    }
}
